package com.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;

/**
 * @Description TODO(这里用一句话描述这个类的作用)
 *
 * @author liuqinghua
 * @date 2025-1-16
 */
public class ApiParse {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(new File("aaa.json")));
        StringBuffer sb = new StringBuffer();
        String line = null;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();
        JSONObject json = JSONObject.parseObject(sb.toString());
        JSONObject paths = json.getJSONObject("paths");
        List<String> keys = new ArrayList<String>();
        keys.addAll(paths.keySet());
        Collections.sort(keys);
        for (String key : keys) {

            JSONObject o = paths.getJSONObject(key);
            JSONObject obj = null;
            String method = "";
            if (o.containsKey("post")) {
                obj = o.getJSONObject("post");
                method = "post";
            } else if (o.containsKey("get")) {
                obj = o.getJSONObject("get");
                method = "get";
            }
            String s = key;
            if (obj != null) {
                String summary = obj.getString("summary");
                if (StringUtils.isNotBlank(summary)) {
                    s = key + "\t" + obj.getString("summary") + "\t" + method+"\t"+obj.getString("responses");
                    if (!(key.startsWith("/encrypt") || key.startsWith("/common") || key.startsWith("/dataSource")
                            || key.startsWith("/dashboard")))
                        System.out.println(s);
                }

            }
        }

    }
}
